<?php

namespace App\Model;

class Video extends Base
{

    public $tableName = 'video';

    public function getVideoData($condition = [], $page = 1, $size = 5)
    {
        $model = $this->create()->where($condition)->order('id', 'DESC')->limit($size * ($page - 1), $size)->withTotalCount();
        $lists = $model->all(null);
        $result = $model->lastQueryResult();
        // 总条数
        $total = $result->getTotalCount();
        return [
            'lists' => $lists,
            'count' => $total,
            'total_page' => $total,
            'page_size' => $size,
        ];
    }

    public function getById($id)
    {
        $result = $this->create()->where(['id' => $id])->get();
        return $result;
    }

    public function getVideoCacheData($condition = [])
    {
        $result = $this->create()->where($condition)->order('id', 'DESC')->all();
        return $result;
    }

}